import scrapy
from ..items import DoubiItem
from json import loads


class DoubiSpider(scrapy.Spider):
    name = 'doubi'
    allowed_domains = ['dbbqb.com']
    # 抓包的请求，返回的为JSON数据
    start_urls = ['http://www.dbbqb.com/api/group/241/detail']

    def parse(self, response):
        # print(response.text)
        data = loads(response.text)
        pre_url = 'http://image.dbbqb.com/'

        for u in data.get('details'):
            yield {
                'image_urls':  pre_url+u.get("path"),
                'img_name': u.get("desc"),
            }

        # img_url = response.xpath("//div//li[@class='jss2']/@src").extract_first()
        # item = DoubiItem()
        # item["img_urls"] = img_url
        # yield item
